import pandas as pd
df=pd.DataFrame(
    { "语文":[4,5,6],
"数学":[4,5,6],
"英语":[4,5,6]},
index=["张三","李四","王五"])

df2=pd.DataFrame(
 { "语文":[4,5,6],
"数学":[4,5,6],
"英语":[4,5,6]},
index=["王六","刘启","赵八"])
df3=df.query("语文>4 and 数学>5")
df3=df.iloc[0:2,[0,1]]

print(df3)
#df_melted = df1.reset_index().melt(
  # id_vars='index', var_name='科目', value_name='成绩')
#df_pivoted = df_melted.pivot(index='index', columns='科目', values='成绩')
#print(df_pivoted)

## 1. pd.melt(df)
print("1. 使用 pd.melt(df) 将列转换为行：")
melted_df = pd.melt(df.reset_index(), id_vars='index')
melted_df.columns = ['姓名', '科目', '成绩']
print(melted_df)

# 2. df.pivot(columns='var', values='val')
print("\n2. 使用 pivot 将行转换为列：")
pivoted_df = melted_df.pivot(index='姓名', columns='科目', values='成绩')
print(pivoted_df)

# 3. pd.concat([df, df2])
print("\n3. 使用 pd.concat([df, df2]) 追加行：")
concatenated_rows = pd.concat([df, df2])
print(concatenated_rows)

# 4. pd.concat([df, df2], axis=1)
print("\n4. 使用 pd.concat([df, df2], axis=1) 追加列：")
concatenated_columns = pd.concat([df, df2], axis=1)
print(concatenated_columns)